package work.jame.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import work.jame.blog.framework.result.PageResult;
import work.jame.blog.framework.utils.SqlUtils;
import work.jame.blog.pojo.Bulletin;
import work.jame.blog.mapper.BulletinMapper;
import work.jame.blog.service.BulletinService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Jame
 * @since 2023-05-18
 */
@Service
public class BulletinServiceImpl extends ServiceImpl<BulletinMapper, Bulletin> implements BulletinService {


    @Override
    public List<Bulletin> queryLimit10() {
        QueryWrapper<Bulletin> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("top");
        Page<Bulletin> page = new Page<>(1, 10);
        page = this.page(page, wrapper);
        if (page.getTotal() != 0) {
            return page.getRecords();
        }
        return null;
    }

    @Override
    public PageResult<Bulletin> searchBulletinByKeyword(String keyword, Long pageNumber, Long pageSize) {
        QueryWrapper<Bulletin> wrapper = new QueryWrapper<>();
        wrapper.like("title", keyword);
        Page<Bulletin> page = new Page<>(pageNumber, pageSize);
        return SqlUtils.fillPageResult(this.page(page, wrapper));
    }
}
